<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="laravel-升级索引" tabindex="-1"><a class="header-anchor" href="#laravel-升级索引"><span>Laravel 升级索引</span></a></h2>
<ul>
<li><a href="#upgrade-5.5.0">从 5.4 升级至 5.5.0</a></li>
</ul>
<h2 id="从-5-4-升级到-5-5-0" tabindex="-1"><a class="header-anchor" href="#从-5-4-升级到-5-5-0"><span>从 5.4 升级到 5.5.0</span></a></h2>
<h4 id="预计升级耗时-1小时" tabindex="-1"><a class="header-anchor" href="#预计升级耗时-1小时"><span>预计升级耗时：1小时</span></a></h4>
<blockquote>
<p>{note}我们尽量记录每一个可能的破坏性变化。但因为其中一些不兼容变更只存在于框架很不起眼的地方，事实上只有一小部分可能会影响到你的应用程序。</p>
</blockquote>
<h3 id="更新依赖" tabindex="-1"><a class="header-anchor" href="#更新依赖"><span>更新依赖</span></a></h3>
<p>在 <code v-pre>composer.json</code> 文件中将 <code v-pre>laravel/framework</code> 更新为 <code v-pre>5.5.*</code> 。 此外，你还应该将 <code v-pre>phpunit/phpunit</code> 依赖关系更新到 <code v-pre>~6.0</code>。</p>
<blockquote>
<p>{tip} 如果你是通过使用 <code v-pre>laravel new</code> 来安装 Laravel 程序，则应该使用命令 <code v-pre>composer global update</code> 来更新 Laravel 安装程序包。</p>
</blockquote>
<h4 id="laravel-dusk" tabindex="-1"><a class="header-anchor" href="#laravel-dusk"><span>Laravel Dusk</span></a></h4>
<p>Laravel Dusk <code v-pre>2.0.0</code> 已经发布，该版本同时兼容 Laravel 5.5 和 Chrome 的 headless 模式测试。</p>
<h4 id="pusher" tabindex="-1"><a class="header-anchor" href="#pusher"><span>Pusher</span></a></h4>
<p>Pusher 事件广播驱动现在需要 <code v-pre>~3.0</code> 版本的 Pusher SDK。</p>
<h3 id="artisan" tabindex="-1"><a class="header-anchor" href="#artisan"><span>Artisan</span></a></h3>
<h4 id="fire-方法" tabindex="-1"><a class="header-anchor" href="#fire-方法"><span><code v-pre>fire</code> 方法</span></a></h4>
<p>该方法已重命名为 <code v-pre>handle</code> 方法。</p>
<h4 id="optimize-命令" tabindex="-1"><a class="header-anchor" href="#optimize-命令"><span><code v-pre>optimize</code> 命令</span></a></h4>
<p>随着对 PHP 操作码缓存的最新改进，不再需要优化 Artisan 命令。你应该从部署脚本中删除对此命令的任何引用，因为它在未来的 Laravel 版本中会被删除。</p>
<h3 id="用户授权" tabindex="-1"><a class="header-anchor" href="#用户授权"><span>用户授权</span></a></h3>
<h4 id="authorizeresouce-控制器方法" tabindex="-1"><a class="header-anchor" href="#authorizeresouce-控制器方法"><span><code v-pre>authorizeResouce</code> 控制器方法</span></a></h4>
<p>当将一个大驼峰命名的模型名称传递给 <code v-pre>authorizeResource</code> 方法时，为了和资源控制器的行为相匹配，生成的路由会用蛇形命名法来命名。</p>
<h4 id="before-策略方法" tabindex="-1"><a class="header-anchor" href="#before-策略方法"><span><code v-pre>before</code> 策略方法</span></a></h4>
<p>如果类中不包含与给定名称相匹配的方法，则不会调用策略类的 <code v-pre>before</code> 方法。</p>
<h3 id="缓存" tabindex="-1"><a class="header-anchor" href="#缓存"><span>缓存</span></a></h3>
<h4 id="数据库驱动" tabindex="-1"><a class="header-anchor" href="#数据库驱动"><span>数据库驱动</span></a></h4>
<p>如果你正在使用数据库缓存驱动，那在你第一次部署升级至 Laravel 5.5时，应该先运行 <code v-pre>php artisan cache:clear</code> 命令。</p>
<h3 id="eloquent" tabindex="-1"><a class="header-anchor" href="#eloquent"><span>Eloquent</span></a></h3>
<h4 id="belongstomany-方法" tabindex="-1"><a class="header-anchor" href="#belongstomany-方法"><span><code v-pre>belongsToMany</code> 方法</span></a></h4>
<p>如果你在 Eloquent 模型中重写了 <code v-pre>belongsToMany</code> 方法，应该更新方法签名来映射新增的参数：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 定义多对多关系。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$related</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$table</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$foreignPivotKey</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$relatedPivotKey</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$parentKey</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$relatedKey</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$relation</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Database<span class="token punctuation">\</span>Eloquent<span class="token punctuation">\</span>Relations<span class="token punctuation">\</span>BelongsToMany</span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">belongsToMany</span><span class="token punctuation">(</span><span class="token variable">$related</span><span class="token punctuation">,</span> <span class="token variable">$table</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span> <span class="token variable">$foreignPivotKey</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span></span>
<span class="line">                              <span class="token variable">$relatedPivotKey</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span><span class="token variable">$parentKey</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span></span>
<span class="line">                              <span class="token variable">$relatedKey</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">,</span> <span class="token variable">$relation</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">//</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="模型的-is-方法" tabindex="-1"><a class="header-anchor" href="#模型的-is-方法"><span>模型的 <code v-pre>is</code> 方法</span></a></h4>
<p>如果你重写了 Eloquent 模型的 <code v-pre>is</code> 方法 ，则应该从该方法中删除 <code v-pre>Model</code> 的类型提示。这将允许 <code v-pre>is</code> 方法接受 <code v-pre>null</code> 作为参数。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 确定两个模型是否具有相同的ID并且属于同一个表。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Database<span class="token punctuation">\</span>Eloquent<span class="token punctuation">\</span>Model<span class="token punctuation">|</span><span class="token keyword">null</span></span>  <span class="token parameter">$model</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">bool</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">is</span><span class="token punctuation">(</span><span class="token variable">$model</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">//</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="模型-events-属性" tabindex="-1"><a class="header-anchor" href="#模型-events-属性"><span>模型 <code v-pre>$events</code> 属性</span></a></h4>
<p>模型上的 <code v-pre>$events</code> 属性应该重命名为 <code v-pre>$dispatchesEvents</code>。由于大量用户需要定义事件关系，导致与旧属性名称的冲突，因此进行了更改。</p>
<h4 id="中间表-parent-属性" tabindex="-1"><a class="header-anchor" href="#中间表-parent-属性"><span>中间表 <code v-pre>$parent</code> 属性</span></a></h4>
<p><code v-pre>Illuminate\Database\Eloquent\Relations\Pivot</code> 类中受保护的 <code v-pre>$parent</code> 属性已被重命名为 <code v-pre>$pivotParent</code> 。</p>
<h4 id="关联-create-方法" tabindex="-1"><a class="header-anchor" href="#关联-create-方法"><span>关联 <code v-pre>create</code> 方法</span></a></h4>
<p><code v-pre>BelongsToMany</code>、<code v-pre>HasOneOrMany</code> 以及 <code v-pre>MorphOneOrMany</code> 类中的 <code v-pre>create</code> 方法已被修改为 <code v-pre>$attributes</code> 参数提供默认值。如果你重写了这些方法，你应该更新你的签名来匹配新的定义。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">create</span><span class="token punctuation">(</span><span class="token keyword type-hint">array</span> <span class="token variable">$attributes</span> <span class="token operator">=</span> <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token comment">//</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="软删除模型" tabindex="-1"><a class="header-anchor" href="#软删除模型"><span>软删除模型</span></a></h4>
<p>删除 「软删除」 模型时，模型上的 <code v-pre>exists</code> 属性将保持为 <code v-pre>true</code> 。</p>
<h4 id="withcount-列格式化" tabindex="-1"><a class="header-anchor" href="#withcount-列格式化"><span><code v-pre>withCount</code> 列格式化</span></a></h4>
<p>当使用别名时，<code v-pre>withCount</code> 方法将不再自动将 <code v-pre>_count</code> 附加到生成的列名称上。例如，在 Laravel 5.4 中，以下查询会将 <code v-pre>bar_count</code> 列添加到查询中：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">withCount</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'foo as bar'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>但是在 Laravel 5.5 中，别名将严格按照给定的方式使用。如果要将 <code v-pre>_count</code> 追加到结果列，则必须在定义别名时指定该后缀：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token variable">$users</span> <span class="token operator">=</span> <span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">withCount</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'foo as bar_count'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">get</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="异常格式" tabindex="-1"><a class="header-anchor" href="#异常格式"><span>异常格式</span></a></h3>
<p>在 Laravel 5.5 中，所有的异常（包括验证异常）都被异常处理程序转换成 HTTP 响应。另外，验证错误默认返回的 JSON 格式已经更改。新格式遵循以下规则：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token string double-quoted-string">"message"</span><span class="token punctuation">:</span> <span class="token string double-quoted-string">"The given data was invalid."</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string double-quoted-string">"errors"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span></span>
<span class="line">        <span class="token string double-quoted-string">"field-1"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string double-quoted-string">"Error 1"</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string double-quoted-string">"Error 2"</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string double-quoted-string">"field-2"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string double-quoted-string">"Error 1"</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string double-quoted-string">"Error 2"</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>但是，如果你想沿用 Laravel 5.4 错误提示的 JSON 格式，则可以将以下方法添加到 <code v-pre>App\Exceptions\Handler</code> 类中：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Validation<span class="token punctuation">\</span>ValidationException</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 将验证异常转换成 JSON 响应</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span>  <span class="token parameter">$request</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Validation<span class="token punctuation">\</span>ValidationException</span>  <span class="token parameter">$exception</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>JsonResponse</span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">invalidJson</span><span class="token punctuation">(</span><span class="token variable">$request</span><span class="token punctuation">,</span> <span class="token class-name type-declaration">ValidationException</span> <span class="token variable">$exception</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">return</span> <span class="token function">response</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">json</span><span class="token punctuation">(</span><span class="token variable">$exception</span><span class="token operator">-></span><span class="token function">errors</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token variable">$exception</span><span class="token operator">-></span><span class="token property">status</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="json-身份验证尝试" tabindex="-1"><a class="header-anchor" href="#json-身份验证尝试"><span>JSON 身份验证尝试</span></a></h4>
<p>此更改也会影响通过 JSON 进行的身份验证尝试的验证错误返回的格式。在 Laravel 5.5 中，身份验证失败的 JSON 将按照上述新的格式约定返回错误消息。</p>
<h4 id="表单请求注意事项" tabindex="-1"><a class="header-anchor" href="#表单请求注意事项"><span>表单请求注意事项</span></a></h4>
<p>现在自定义了单个表单请求的响应格式，应重写该表单请求的 <code v-pre>failedValidation</code> 方法 ，并抛出一个包含自定义响应的 <code v-pre>HttpResponseException</code> 实例。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Exceptions<span class="token punctuation">\</span>HttpResponseException</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 处理失败的验证尝试。</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Contracts<span class="token punctuation">\</span>Validation<span class="token punctuation">\</span>Validator</span>  <span class="token parameter">$validator</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">void</span></span></span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@throws</span> <span class="token class-name"><span class="token punctuation">\</span>Illuminate<span class="token punctuation">\</span>Validation<span class="token punctuation">\</span>ValidationException</span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">protected</span> <span class="token keyword">function</span> <span class="token function-definition function">failedValidation</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Validator</span> <span class="token variable">$validator</span><span class="token punctuation">)</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token keyword">throw</span> <span class="token keyword">new</span> <span class="token class-name">HttpResponseException</span><span class="token punctuation">(</span><span class="token function">response</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">json</span><span class="token punctuation">(</span><span class="token operator">...</span><span class="token punctuation">,</span> <span class="token number">422</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="文件系统" tabindex="-1"><a class="header-anchor" href="#文件系统"><span>文件系统</span></a></h3>
<h4 id="files-方法" tabindex="-1"><a class="header-anchor" href="#files-方法"><span><code v-pre>files</code> 方法</span></a></h4>
<p><code v-pre>files</code> 方法与 <code v-pre>allFiles</code> 方法类似，会返回一个 <code v-pre>SqlFileInfo</code> 对象的数组。之前的 <code v-pre>files</code> 方法会返回一个字符串路径名的数组。</p>
<h3 id="邮件" tabindex="-1"><a class="header-anchor" href="#邮件"><span>邮件</span></a></h3>
<h4 id="未使用的参数" tabindex="-1"><a class="header-anchor" href="#未使用的参数"><span>未使用的参数</span></a></h4>
<p>未使用的 <code v-pre>$data</code> 和 <code v-pre>$callback</code> 参数已从 <code v-pre>Illuminate\Contracts\Mail\MailQueue</code> 契约的 <code v-pre>queue</code> 和 <code v-pre>later</code> 方法中删除</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * 在队列中发送新的电子邮件</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">array</span><span class="token punctuation">|</span>MailableContract</span>  <span class="token parameter">$view</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$queue</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">mixed</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">queue</span><span class="token punctuation">(</span><span class="token variable">$view</span><span class="token punctuation">,</span> <span class="token variable">$queue</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token doc-comment comment">/**</span>
<span class="line"> * n 秒后在队列中发送新的电子邮件</span>
<span class="line"> *</span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>DateTimeInterface<span class="token punctuation">|</span><span class="token punctuation">\</span>DateInterval<span class="token punctuation">|</span><span class="token keyword">int</span></span>  <span class="token parameter">$delay</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span><span class="token punctuation">|</span><span class="token keyword">array</span><span class="token punctuation">|</span>MailableContract</span>  <span class="token parameter">$view</span></span>
<span class="line"> * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token keyword">string</span></span>  <span class="token parameter">$queue</span></span>
<span class="line"> * <span class="token keyword">@return</span> <span class="token class-name"><span class="token keyword">mixed</span></span></span>
<span class="line"> */</span></span>
<span class="line"><span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">later</span><span class="token punctuation">(</span><span class="token variable">$delay</span><span class="token punctuation">,</span> <span class="token variable">$view</span><span class="token punctuation">,</span> <span class="token variable">$queue</span> <span class="token operator">=</span> <span class="token constant">null</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="请求" tabindex="-1"><a class="header-anchor" href="#请求"><span>请求</span></a></h3>
<h4 id="has-方法" tabindex="-1"><a class="header-anchor" href="#has-方法"><span><code v-pre>has</code> 方法</span></a></h4>
<p><code v-pre>$request-&gt;has</code> 方法现在对于空字符串和 <code v-pre>null</code> 将返回 <code v-pre>true</code>。新添加的 <code v-pre>$request-&gt;filled</code> 方法提供了之前的 <code v-pre>has</code> 方法的行为。</p>
<h4 id="intersect-方法" tabindex="-1"><a class="header-anchor" href="#intersect-方法"><span><code v-pre>intersect</code> 方法</span></a></h4>
<p><code v-pre>intersect</code> 方法已被移除。你只需在调用 <code v-pre>$request-&gt;only</code> 时使用 <code v-pre>array_filter</code> 来代替该方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token function">array_filter</span><span class="token punctuation">(</span><span class="token variable">$request</span><span class="token operator">-></span><span class="token function">only</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'foo'</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="only-方法" tabindex="-1"><a class="header-anchor" href="#only-方法"><span><code v-pre>only</code> 方法</span></a></h4>
<p><code v-pre>only</code> 方法现在只会返回请求中实际存在的属性。如果你想保留该方法的旧功能，可以使用 <code v-pre>all</code> 方法来替代。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token variable">$request</span><span class="token operator">-></span><span class="token function">all</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'foo'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="辅助函数-request" tabindex="-1"><a class="header-anchor" href="#辅助函数-request"><span>辅助函数 <code v-pre>request()</code></span></a></h4>
<p>辅助函数 <code v-pre>request</code> 将不再检索嵌套的键。如果有需要，你可以使用 <code v-pre>request</code> 中的 <code v-pre>input</code> 方法来达成此目的：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token function">request</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">input</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'filters.date'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="测试" tabindex="-1"><a class="header-anchor" href="#测试"><span>测试</span></a></h3>
<h4 id="认证声明" tabindex="-1"><a class="header-anchor" href="#认证声明"><span>认证声明</span></a></h4>
<p>一些认证断言被重命名为与框架的其他断言更好的一致性：</p>
<ul>
<li><code v-pre>seeIsAuthenticated</code> 被重命名为 <code v-pre>assertAuthenticated</code> ；</li>
<li><code v-pre>dontSeeIsAuthenticated</code> 被重命名为 <code v-pre>assertGuest</code> ；</li>
<li><code v-pre>seeIsAuthenticatedAs</code> 被重命名为 <code v-pre>assertAuthenticatedAs</code> ；</li>
<li><code v-pre>seeCredentials</code> 被重命名为 <code v-pre>assertCredentials</code> ；</li>
<li><code v-pre>dontSeeCredentials</code> 被重命名为 <code v-pre>assertInvalidCredentials</code> 。</li>
</ul>
<h4 id="伪造邮件" tabindex="-1"><a class="header-anchor" href="#伪造邮件"><span>伪造邮件</span></a></h4>
<p>如果你使用伪造 Mail 来请求中是否有可用的<strong>队列</strong> ，则应该使用 <code v-pre>Mail::assertQueued</code> 来代替 <code v-pre>Mail::assertSent</code> 。 这种区别允许你明确声明邮件已在队列中等待发送，而不是在请求期间发送。</p>
<h3 id="翻译" tabindex="-1"><a class="header-anchor" href="#翻译"><span>翻译</span></a></h3>
<h4 id="loaderinterface" tabindex="-1"><a class="header-anchor" href="#loaderinterface"><span><code v-pre>LoaderInterface</code></span></a></h4>
<p><code v-pre>Illuminate\Translation\LoaderInterface</code> 该接口已被移动至 <code v-pre>Illuminate\Contracts\Translation\Loader</code>。</p>
<h3 id="验证" tabindex="-1"><a class="header-anchor" href="#验证"><span>验证</span></a></h3>
<h4 id="验证方法" tabindex="-1"><a class="header-anchor" href="#验证方法"><span>验证方法</span></a></h4>
<p>所有的验证器的验证方法已由 <code v-pre>protected</code> 改为 <code v-pre>public</code> 。</p>
<h3 id="视图" tabindex="-1"><a class="header-anchor" href="#视图"><span>视图</span></a></h3>
<h4 id="动态的-「with」-变量" tabindex="-1"><a class="header-anchor" href="#动态的-「with」-变量"><span>动态的 「with」 变量</span></a></h4>
<p>当允许动态的 <code v-pre>__call</code> 方法与视图共享变量时，该变量将会自动使用驼峰式命名。举例如下：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'pool'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">withMaximumVotes</span><span class="token punctuation">(</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p><code v-pre>maximumVotes</code> 变量可以在模板中访问，如下所示：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token punctuation">{</span><span class="token punctuation">{</span> <span class="token variable">$maximumVotes</span> <span class="token punctuation">}</span><span class="token punctuation">}</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="其他" tabindex="-1"><a class="header-anchor" href="#其他"><span>其他</span></a></h3>
<p>你还可以查看 <code v-pre>laravel/laravel</code> 在 GitHub 中的更改。虽然这些更改不是必需的，但你可能希望将这些文件与应用程序保持同步。本升级指南中将介绍其中一些更改，而其他的则不会被介绍，例如更改配置文件或注释。你可以使用 <a href="https://github.com/laravel/laravel/compare/5.4...master" target="_blank" rel="noopener noreferrer">GitHub 的比较工具</a> 轻松查看你在意的变更的内容。</p>
<h2 id="译者署名" tabindex="-1"><a class="header-anchor" href="#译者署名"><span>译者署名</span></a></h2>
<table>
<thead>
<tr>
<th>用户名</th>
<th>头像</th>
<th>职能</th>
<th>签名</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://learnku.com/users/18485" target="_blank" rel="noopener noreferrer">@我做我的梦</a></td>
<td><img src="https://cdn.learnku.com/uploads/avatars/18485_1503368993.jpeg?imageView2/1/w/100/h/100" alt="100"></td>
<td>翻译</td>
<td>A new to Laravel，and hope Laravel is the last framework for me.</td>
</tr>
<tr>
<td><a href="https://learnku.com/users/5350" target="_blank" rel="noopener noreferrer">@JokerLinly</a></td>
<td><img src="https://cdn.learnku.com/uploads/avatars/5350_1481857380.jpg" alt="5350_1481857380.jpg"></td>
<td>Review</td>
<td>Stay Hungry. Stay Foolish.</td>
</tr>
</tbody>
</table>
<hr>
<blockquote>
<p>{note} 欢迎任何形式的转载，但请务必注明出处，尊重他人劳动共创开源社区。</p>
<p>转载请注明：本文档由 Laravel China 社区 <a href="https://laravel-china.org/" target="_blank" rel="noopener noreferrer">laravel-china.org</a> 组织翻译，详见 <a href="https://learnku.com/laravel/t/5756/laravel-55-document-translation-call-come-and-join-the-translation" target="_blank" rel="noopener noreferrer">翻译召集帖</a>。</p>
<p>文档永久地址： <a href="https://learnku.com/docs/laravel" target="_blank" rel="noopener noreferrer">《Laravel 中文文档》</a></p>
</blockquote>
</div></template>


